/**
 * a script of a dialog box used before deleting a student
 */

$(document).ready(function(){
  $(".delete").click(function(){
	  var name = $(this).attr('id');
	  $("#dialog").dialog({ buttons: [
	                                   {
	                                       text: "Ok",
	                                       click: function() { 
	                                    	   $.ajax("/salonmorandsmigi/UserServlet?action=delete&name="+name,{
	                                    		   type: "GET",
	                                    		   success: function(){
	                                    		     $("#"+name).remove();
	                                    		     if ($("table").find("tr").length==0){
	                                    		    	 $("table").remove();
	                                    		    	 $("#students").append("There are no Students registered to the Site");
	                                    		     }
	                                    		   },
	                                    		   error: function(){
	                                    			 alert("error deleting");  
	                                    		   }
	                                    		 });
	                                    	   $(this).dialog("close");
	                                       }
	                                   },
	                                   {
	                                	   text: "Cancel",
	                                	   click: function() { $(this).dialog("close");}
	                                   }
	                                  ], 
	  						show: "fold",
	  						hide: "explode"
	  					 });
  });
});